package com.wood.life.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.night.common.entity.life.Answer;
import com.night.common.entity.life.Goods;
import com.wood.life.mapper.AnswerMapper;
import com.wood.life.mapper.GoodsMapper;
import com.wood.life.service.AnswerService;
import com.wood.life.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * author: dz
 * 2022-10-18-20:57
 */
@Service
@Transactional
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    GoodsMapper GoodsMapper;

    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public void add(Goods goods) {
        GoodsMapper.insert(goods);
        ListOperations opsForList = redisTemplate.opsForList();
        for (int i = 0; i < goods.getNumber(); i++) {
            opsForList.leftPush(goods.getName(), goods);
        }

    }

    @Override
    public List<Goods> getByCondition(Goods goods) {
        return GoodsMapper.getByCondition(goods);
    }

    @Override
    public void updateById(Goods goods) {
        GoodsMapper.updateById(goods);
    }

    @Override
    public void deleteById(Integer id) {
        GoodsMapper.deleteById(id);
    }

}
